<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div>
      <a-form @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="6" :sm="12">
            <a-form-item label="账号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input style="width:100%;" placeholder="请输入账号模糊查询" v-model="queryParam.username"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="12">
            <a-form-item label="姓名" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input placeholder="请输入姓名模糊查询" v-model="queryParam.nickname"></a-input>
            </a-form-item>
          </a-col>
          <!-- <template v-if="toggleSearchStatus">
            <a-col :md="6" :sm="8">
              <a-form-item label="用户状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-select v-model="queryParam.status" style="width:100%;" placeholder="请选择">
                  <a-select-option value="">请选择</a-select-option>
                  <a-select-option value="1">正常</a-select-option>
                  <a-select-option value="2">冻结</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
          </template> -->

          <a-col :md="6" :sm="8">
            <a-form-item>
              <a-button type="primary" @click="searchQuery()" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset()" icon="reload" style="margin-left: 8px">重置</a-button>
              <!-- <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a> -->
            </a-form-item>
          </a-col>

        </a-row>
      </a-form>
    </div>

    <!-- table区域-begin -->
    <div>
      <vxe-grid
        id="UserList"
        ref="vxeTable"
        v-bind="gridOptions"
        v-on="listeners"
      >
      <template #dictText={row,column}>
        <span>{{getDictText(row,column)}}</span>
      </template>
      <template #action="{ row }">
        <template>
          <a @click="handleEdit(row)" >编辑</a>
          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">
              更多 <a-icon type="down"/>
            </a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a href="javascript:;" @click="handleDetail(row)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a href="javascript:;" @click="handleEditPassword(row)">密码</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(row.username)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </template>
      </template>
    </vxe-grid>
    </div>
    <!-- table区域-end -->
    <user-modal ref="modalForm" @ok="modalFormOk"></user-modal>
    <UpdatePassModal ref="UpdatePassModal" @ok="modalFormOk" />
  </a-card>
</template>

<script>
import UserModal from './modules/UserModal'
import UpdatePassModal from './modules/UpdatePassModal'
import VxeTableListMixin from '@/mixins/VxeTableListMixin'
import { deleteAction } from '@/services/manage'
export default {
  name: 'UserList',
  components: {
    UserModal,
    UpdatePassModal
  },
  mixins: [VxeTableListMixin],
  data() {
    return {
      columns: [
        {
          title: '用户账号',
          field: 'username',
          sorter: true
        },
        {
          title: '用户姓名',
          field: 'nickname'
        },
        // {
        //   title: '是否有效',
        //   field: 'accountNonExpired',
        //   slots: { default: 'dictText' }
        // },
        // {
        //   title: '可用',
        //   field: 'accountNonLocked',
        //   slots: { default: 'dictText' }
        // },
        {
          title: '是否管理员',
          field: 'administrator',
          slots: { default: 'dictText' }
        },
        // {
        //   title: '凭证可用',
        //   field: 'credentialsNonExpired',
        //   slots: { default: 'dictText' }
        // },
        {
          title: '操作',
          slots: { default: 'action' },
          width: 170
        }
      ],
      url: {
        list: '/user/list',
        delete: '/user/delete/',
        deleteBatch: '/user/deleteBatch',
        exportXlsUrl: '/user/exportXls',
        importExcelUrl: '/user/importExcel'
      }
    }
  },
  methods: {
    getDictText(row, column) {
      return row[column.property] === true ? '是' : '否'
    },
    handleDelete: function(username) {
      if (!this.url.delete) {
        this.$message.error('请设置url.delete属性!')
        return
      }
      var that = this
      deleteAction(that.url.delete, { username: username }).then((res) => {
        if (res.success) {
          that.$message.success(res.message)
          that.loadData()
        } else {
          that.$message.warning(res.message)
        }
      })
    },
    handleEditPassword(row) {
      this.$refs.UpdatePassModal.edit(row)
    }
  }
}
</script>

